package com.ice.cloud.comm.resp;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

// 统一响应类型
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {

    private Integer code;
    private  String msg;
    private T data;
    // 返回
    // 返回操作成功 ，带响应数据
    public static <E> R<E> success(E data){
        R<E> R = new R<>();
        R.setCode(ReturnCodeEnum.RC200.getCode());
        R.setMsg(ReturnCodeEnum.RC200.getMessage());
        R.setData(data);
        return R;
    }

    //  返回操作成功 ，不带返回结果
    public static <E> R<E> success(){
        R<E> R = new R<>();
        R.setCode(ReturnCodeEnum.RC200.getCode());
        R.setMsg(ReturnCodeEnum.RC200.getMessage());
        return R;
    }

    // 失败
    public static <E> R<E> error(int code,String message){
        R<E> R = new R<E>();
        R.setCode(code);
        R.setMsg(message);
        return R;
    }
}
